package com.lancoo.lancooimageloader.glide;

import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;

import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.lancoo.lancooimageloader.LancooImageCallback;

/**
 * Created by gongwq on 2017/6/12 0012.
 */

public class GlideImageCallback<T extends Drawable> implements RequestListener<T> {//, RequestListener<Drawable> {
    private LancooImageCallback mImageCallback;

    public GlideImageCallback(LancooImageCallback mImageCallback) {
        this.mImageCallback = mImageCallback;
    }

    @Override
    public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<T> target, boolean b) {
        if (mImageCallback != null) {
            mImageCallback.onError(e, b);
            mImageCallback.onFinished();
        }
        return false;
    }

    @Override
    public boolean onResourceReady(T t, Object o, Target<T> target, DataSource dataSource, boolean b) {
        if (mImageCallback != null) {
            mImageCallback.onSuccess(t);
            mImageCallback.onFinished();
        }
        return false;
    }
}
